import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
    state: { //数据源  

        // 公共
        comm: {
            loading: { //这个数据源映射到了header里面
                title: '', // 标题,
                isShow: false //是否显示   
            },
            isHeader: {
                isShow: true
            },
            showType: {
                type: ""
            }
        }
    },
    mutations: {
        /*
         * 修改header的信息
         *
         * */
        changeLoading: (state, data) => {
            Object.assign(store.getters.getLoading, data) //使用getters获取处理后的数据源然后进行浅拷贝
        },
        changeHeader: (state, data) => {
            Object.assign(store.getters.getHeader, data)
        },
        changeType: (state, data) => {
            Object.assign(store.getters.getType, data)
        }

    },
    actions: {

    },
    getters: {
        getLoading: state => { //处理数据源
            return Object.assign(state.comm.loading)
        },
        getHeader: state => {
            return Object.assign(state.comm.isHeader)
        },
        getType: state => {
            return Object.assign(state.comm.showType)
        }
    }
})
export default store